
* -- This Stata code replicates the tables in  
* -- "Activity shocks and corporate liquidity: the role of trade credit"(forthcoming RCFS)
* -- By Benjamin Bureau, Anne Duquerroy and Frédéric Vinas

* -- For confidentiality reason, the database of the paper cannot be provided as Payment Defaults data (called the CIPE database below)
* -- cannot be shared. 
* --  The other database are accessible through the CASD. See https://www.comite-du-secret.fr/procedure-fr/procedure-via-cdap for the procedure to access
* --  the data through the CASD.
* --  Our final database is built from the following four data sets maintained by the Banque de France :
* (i) 	the CIPE database that records all payment defaults on trade bills for French firms
* (ii) 	the FIBEN database that gathers financial statements of a wide set of nonfinancial firms operating in France,
* (iii) the Central Credit register database 
* (iv)  a database on bankruptcy and liquidation procedures

* IMPORTANT: 
* The pseudo-dataset is provided only to illustrate the format of the original data. 
* Values are random, so the pseudo-dataset does NOT reproduce the results reported in the paper.


* The pseudo-dataset equivalents are the following :
* 		$mypath2\regression_sample_final 		--> 	$mypath2\basic_pseudo_sample
*		$mypath2\regression_long_period 		--> 	$mypath2\basic_pseudo_long_period, replace
*		$mypath2\reg_cie_unbalanced_exhaustive	--> 	$mypath2\basic_pseudo_sample_unbalanced


* TABLE OF CONTENTS:
* 1.	DESCRIPTION OF THE MAIN VARIABLES 
* 2.	REGRESSION TABLES		: Tables 6 to 14  
* 3.	DESCRIPTIVE STATISTICS 	: Tables 2 to 5   	  	  				  
* 4.	FIGURES	

	* Indicate your directory path below
	* global mypath2  "xxx\xxx
	* global datapath "xxx\xxx
		
	global control		 		cash_ta 	  leverage 		 size
	global control_post			cash_ta_post  leverage_post  size_post
	global additional_control   share_st_lag3  ratio_douteux  altman_w  altman_post douteux_post st_post	
	global regspec_c  			"absorb (siren ind_month) vce (cluster i.siren)"			

	use $mypath2\basic_pseudo_sample, clear
	
	****************************************************************************
	*																		   *
	*				1.	DESCRIPTION OF THE MAIN VARIABLES				   	   *
	*																		   *
	****************************************************************************
	
		lab var siren 		   		"Firm ID"
		lab var firm_with_ip   		"Dummy variable set to one if the firm defaults on paying a trade bill"
		lab var cash_ta 			"Cash holdings to assets"
		lab var leverage 			"Leverage"
		lab var size				"Size"
		lab var leverage_post   	"Leverage $\times$ Post"
		lab var	size_post   		"Size 	  $\times$ Post"
		lab var ratio_douteux 		"Non performing loans (NPL)to total loans"
		lab var share_st_lag3		"Liquidity needs"
		lab var altman_w       		"Z-score"
		lab var douteux_post 		"NPL $\times$ Post"
		lab var st_post    			"Liquidity needs $\times$ Post"
		lab var altman_post     	"Z-score $\times$ Post"										
		lab var roa					"Return on assets"

		label var cie 	 	 		"Trade credit (TC) " 
		label var cie_post 	 		"TC $\times$ Post"
		label var cie_march_april	"TC $\times$ March-April"
		label var cie_may_june 		"TC $\times$ May-June"
		label var cie_march_april 	"TC $\times$ March-April"
		label var cie_may_june 		"TC $\times$ May-June"
		
		label var dfac	 	 	 	"Payables " 
		label var dfac_post 	 	"Payables $\times$ Post"
		label var ccca	 		 	"Receivables " 
		label var ccca_post 	 	"Receivables $\times$ Post"
		
		lab var aud_ca				"Amount under default over Sales"
		lab var aud 				"Amount under default, in euros"
		lab var firm_with_ip 		"Payment default dummy"
		lab var nb 					"Number of defaults, per month"	
		
		
	****************************************************************************
	*																		   *
	*			2.			REGRESSION TABLES: Table 6 to 14   				   *
	*																		   *
	****************************************************************************
	
	*****************************************************************************
	*****************************************************************************		
		
	// Table 6 - Does trade credit position explain firms’ payment default during the Covid-19 crisis?
	

	reghdfe firm_with_ip cie  if date < tm(2020m7), $regspec_c
	outreg2 firm_with_ip cie using table6, bdec(4) rdec(3) keep(firm_with_ip cie) excel  /*tex*/ replace label
	
	reghdfe firm_with_ip cie cie_post if date < tm(2020m7), $regspec_c
	outreg2 firm_with_ip cie using table6, bdec(4) rdec(3) keep(firm_with_ip cie cie_post) excel  /*tex*/ append label
	
	reghdfe firm_with_ip cie cie_march cie_may if date < tm(2020m7), $regspec_c
	outreg2 firm_with_ip cie cie_march cie_may using table6, bdec(4) rdec(3) keep(firm_with_ip cie cie_march cie_may ) excel  /*tex*/ append label
	
	* Add covariates 
	reghdfe firm_with_ip cie cie_march cie_may $control  if date < tm(2020m7) , $regspec_c
	outreg2 firm_with_ip cie cie_march cie_may $control using table6, bdec(4) rdec(3) keep(firm_with_ip cie cie_march cie_may $control ) excel  /*tex*/ append label
		
	* Add covariates * Post
	reghdfe firm_with_ip cie cie_march cie_may $control $control_post if date < tm(2020m7) , $regspec_c
	outreg2 firm_with_ip cie cie_march cie_may $control $control_post using table6, bdec(4) rdec(3) keep(firm_with_ip cie cie_march cie_may $control $control_post) excel  /*tex*/ append label
		
	* Additional time varying controls : credit risk and non performing loans ; and share of ST loans
	reghdfe firm_with_ip altman_w altman_post cie cie_march cie_may $control $control_post if date < tm(2020m7) , $regspec_c
	outreg2 firm_with_ip altman_w altman_post cie cie_march cie_may $control $control_post using table6, bdec(4) rdec(3) keep(firm_with_ip altman_w altman_post cie cie_march cie_may $control $control_post) excel  /*tex*/ append label
	
	reghdfe firm_with_ip ratio_douteux douteux_post cie cie_march cie_may $control $control_post if date < tm(2020m7) , $regspec_c
	outreg2 firm_with_ip ratio_douteux douteux_post cie cie_march cie_may $control $control_post using table6, bdec(4) rdec(3) keep(firm_with_ip ratio_douteux douteux_postcie cie_march cie_may $control $control_post) excel  /*tex*/ append label
	
	reghdfe firm_with_ip share_st_lag3 st_post  cie cie_march cie_may $control $control_post if date < tm(2020m7) , $regspec_c
	outreg2 firm_with_ip share_st_lag3 st_post  cie cie_march cie_may $control $control_post using table6, bdec(4) rdec(3) keep(firm_with_ip share_st_lag3 st_post  cie cie_march cie_may $control $control_post) excel  /*tex*/ append label
	
	* All
	reghdfe firm_with_ip cie cie_march cie_may $control $control_post $additional_control    if date < tm(2020m7) , $regspec_c
	outreg2 firm_with_ip cie cie_march cie_may $control $control_post $additional_control  using table6, bdec(4) rdec(3) keep(firm_with_ip cie cie_march cie_may $control $control_post $additional_control) excel  /*tex*/ append label
	
	*****************************************
	* List of firms in baseline regression  *
	*****************************************
	
	// Table 7 - Sectoral analysis: does trade credit position explain firms’ payment default during the Covid-19 crisis?
		
		preserve 
	
		gen 	main_sector="Agriculture" 		 if naf>=00 & naf<=04
		replace main_sector="Manufacturing" 	 if naf>=05 & naf<=39
		replace main_sector="Construction" 		 if naf>=41 & naf<=43
		replace main_sector="Transport, storage" if naf>=49 & naf<=53
		replace main_sector="Accomodation, food" if naf>=55 & naf<=56
		replace main_sector="Information" 		 if naf>=58 & naf<=63 
		replace main_sector="Real estate" 		 if naf>=68 & naf<=68
		replace main_sector="Corporate Services" if naf>=69 & naf<=82 
		replace main_sector="Health" 			 if naf>=84 & naf<=88
		replace main_sector="Recreation" 		 if naf>=90		
		replace	main_sector="Wholesale trade" 	 if naf==46
		replace main_sector="Retail trade" 		 if naf==47 | naf==45
								
		egen ind_num = group(main_sector)
		
		save $mypath2\temp, replace
		
		use $mypath2\temp, replace
		keep if ind_num == 1
		** -- Above or below median of the distribution of CIE in 2019 within sector
		cap drop cie_ref cie_q
		gen cie_ref = cie_ca if year == 2019
		xtile cie_q = cie_ref if cie_ref != ., nq(4)
		bys siren : egen cie_qmax =max(cie_q)
		drop cie_q
		rename cie_qmax cie_q
		cap drop high* vhigh*
		gen high_tc  = (cie_q > 2)
		** -- High TC 
		cap drop treated*
		gen treated = (high_tc ==1)
		gen treated_march = treated * march_april
		gen treated_may = treated * may_june
		lab var treated_march "Treated $\times$ March-April"
		lab var treated_may   "Treated $\times$ May-June"
		
		reghdfe firm_with_ip treated_march treated_may treated  $additional_control $control $control_post if date < tm(2020m7) , $regspec_c
		outreg2 firm_with_ip treated_march treated_may treated  $additional_control $control $control_post using table7, bdec(4) rdec(3) keep(firm_with_ip treated_march treated_may treated) excel  /*tex*/ replace label
		
		forvalues i = 2(1)12 {
		
		use $mypath2\temp, replace
		keep if ind_num == `i'
		** Above or below median of the distribution of CIE in 2019 within sector
		cap drop cie_ref cie_q
		gen cie_ref = cie_ca if year == 2019
		xtile cie_q = cie_ref if cie_ref != ., nq(4)
		bys siren : egen cie_qmax =max(cie_q)
		drop cie_q
		rename cie_qmax cie_q
		cap drop high* vhigh*
		gen high_tc  = (cie_q > 2)
		** -- High TC 
		cap drop treated*
		gen treated = (high_tc ==1)
		gen treated_march = treated * march_april
		gen treated_may = treated * may_june
		lab var treated_march "Treated $\times$ March-April"
		lab var treated_may   "Treated $\times$ May-June"
		
		reghdfe firm_with_ip treated_march treated_may treated  $additional_control $control $control_post if date < tm(2020m7) , $regspec_c
		outreg2 firm_with_ip treated_march treated_may treated  $additional_control $control $control_post using table7, bdec(4) rdec(3) keep(firm_with_ip treated_march treated_may treated) excel  /*tex*/ append label
	
		}

	// Table 8 - Focus on the retail trade sector
	
	restore, preserve
	
	keep if naf==47 | naf==45
	
	* Open
	reghdfe firm_with_ip cie cie_march_april cie_may_june  $additional_control  $control $control_post if date < tm(2020m7) & com_détail_autorisé==1 , $regspec_c
	outreg2 firm_with_ip cie cie_march_april cie_may_june  $additional_control $control $control_post using table8, bdec(4) rdec(3) keep(firm_with_ip cie cie_march_april cie_may_june) excel  /*tex*/ replace label
	
	* Close
	reghdfe firm_with_ip cie cie_march_april cie_may_june $additional_control  $control $control_post if  date < tm(2020m7)  & com_détail_autorisé==0 , $regspec_c
	outreg2 firm_with_ip cie cie_march_april cie_may_june  $additional_control $control $control_post using table8, bdec(4) rdec(3) keep(firm_with_ip cie cie_march_april cie_may_june) excel  /*tex*/ append label
		
	* DiD - Split high vs low
	gen cie_ref = cie_ca if year == 2019
	xtile cie_q = cie_ref if cie_ref != ., nq(4)
	bys siren : egen cie_qmax =max(cie_q)
	drop cie_q
	rename cie_qmax cie_q
	cap drop high* vhigh*
	gen high_tc  = (cie_q > 2)
		
	* High TC with the retail Trade
	cap drop treated*
	gen treated = (high_tc ==1)
	gen treated_march = treated * march_april
	gen treated_may = treated * may_june
	lab var treated 		"Treatment"
	lab var treated_march 	"High TC $\times$ March-April"
	lab var treated_may		"High TC $\times$ May-June"
	
	* Close		
	reghdfe firm_with_ip treated_march treated_may treated  $additional_control $control $control_post if date < tm(2020m7)& com_détail_autorisé==0  , $regspec_c
	outreg2 firm_with_ip treated_march treated_may treated  $additional_control $control $control_post using table8, bdec(4) rdec(3) keep(firm_with_ip treated_march treated_may treated) excel  /*tex*/ append label
	
	* Open
	reghdfe firm_with_ip treated_march treated_may treated  $additional_control $control $control_post if date < tm(2020m7)& com_détail_autorisé==1  , $regspec_c
	outreg2 firm_with_ip treated_march treated_may treated  $additional_control $control $control_post using table8, bdec(4) rdec(3) keep(firm_with_ip treated_march treated_may treated) excel  /*tex*/ append label

	
	// Table 9 - Effect of firms’ trade credit position on their payment default conditional on financing constraints
	
	restore, preserve
	
	gen  small = (taille_lme_string == "pme" | taille_lme_string == "mic")
		
	** -- Small
	cap drop post_D D
	gen D = small
	gen post_D = D * post
	
	cap drop cie_D_post cie_D
	gen cie_D_post = cie_post * D
	gen cie_D 	= cie * D
	
	lab var cie_D_post   "D $\times$ TC $\times$ Post"
	lab var cie_D		 "TC $\times$ D"
	lab var post_D       "D  $\times$ Post"
	
	reghdfe firm_with_ip cie_D_post post_D cie_D cie cie_post  $additional_control  $control $control_post if date < tm(2020m7),  $regspec_c	
	outreg2 firm_with_ip cie_D_post post_D cie_D cie cie_post  $additional_control  $control $control_post using table9, bdec(4) rdec(3) keep(firm_with_ip cie_D_post post_D cie_D cie cie_post) excel  /*tex*/ replace label
	
	** -- Low rated
	** Drop non rated firms
	keep if rating_jan > 0.5
	cap drop low_rated
	gen low_rated = (rating_jan > 4)
	
	cap drop post_D D
	gen D = low_rated
	gen post_D = D * post
	
	cap drop cie_D_post cie_D
	gen cie_D_post = cie_post * D
	gen cie_D 	= cie * D
	
	lab var cie_D_post   "D $\times$ TC $\times$ Post"
	lab var cie_D		 "TC $\times$ D"
	lab var post_D       "D  $\times$ Post"
	
	reghdfe firm_with_ip cie_D_post cie_post post_D cie_D cie   $additional_control  $control $control_post if date < tm(2020m7),  $regspec_c
	outreg2 firm_with_ip cie_D_post post_D cie_D cie cie_post  $additional_control $control $control_post using table9, bdec(4) rdec(3) keep(firm_with_ip cie_D_post post_D cie_D cie cie_post) excel  /*tex*/ append label
		
	** -- Efficiency
		
		** We classify a firm as capital constrained (high MRPK) if it is above the
		** 4-digit level industry median for the averaged measure.

		restore, preserve
		egen indnum = group(naf4digit)
		foreach var in mrpk1  {
		bys siren : egen mean_`var' = mean(`var')
		}
		replace mean_mrpk1 = 0 if mean_mrpk1 < 0
		save $mypath2\temp.dta, replace
		
		use $mypath2\temp, replace
		keep if indnum ==1
		xtile mrpk1_q = mean_mrpk1, nq(4)
		save $mypath2\ind_mrpk, replace
		
		forvalues industry = 2(1)554 {
		use $mypath2\temp, replace
		keep if indnum ==`industry'
		capture xtile mrpk1_q = mean_mrpk1, nq(4)
		capture append using $mypath2\ind_mrpk.dta
		save $mypath2\ind_mrpk, replace
		}
					
		use $mypath2\ind_mrpk, replace
		keep siren date mean_mrpk* mrpk*
		merge 1:1 siren date using $mypath2/basic_pseudo_sample.dta
		
		foreach var in mean_mrpk1  { 				
		gen high_`var' = ( mrpk1_q > 2) 
		}
		
		cap drop post_D D
		gen D = high_mean_mrpk1 
		gen post_D = D * post
		cap drop cie_D_post cie_D
		gen cie_D_post = cie_post * D
		gen cie_D 	= cie * D
		
		lab var cie_D_post   "D $\times$ TC $\times$ Post"
		lab var cie_D		 "TC $\times$ D"
		lab var post_D       "D  $\times$ Post"
		
		reghdfe firm_with_ip cie_D_post cie_post post_D cie_D cie $additional_control  $control $control_post,  $regspec_c
		outreg2 firm_with_ip cie_D_post post_D cie_D cie cie_post  $additional_control $control $control_post using table9, bdec(4) rdec(3) keep(firm_with_ip cie_D_post post_D cie_D cie cie_post) excel  /*tex*/ append label
	
	** -- Dividend payer if paid dividend in 2018 and 2019	
		restore, preserve
		
		bys siren : egen div_mean =mean(payer)
		gen non_payer =(div_mean ==0)
		cap drop post_D D
		gen D = non_payer
		gen post_D = D * post
		cap drop cie_D_post cie_D
		gen cie_D_post = cie_post * D
		gen cie_D 	= cie * D
		
		lab var cie_D_post   "D $\times$ TC $\times$ Post"
		lab var cie_D		 "TC $\times$ D"
		lab var post_D       "D  $\times$ Post"
		
		reghdfe firm_with_ip cie_D_post post_D cie_D cie cie_post  $additional_control  $control $control_post,  $regspec_c
		outreg2 firm_with_ip cie_D_post post_D cie_D cie cie_post  $additional_control $control $control_post using table9, bdec(4) rdec(3) keep(firm_with_ip cie_D_post post_D cie_D cie cie_post) excel  /*tex*/ append label
	
	** --  Profitability
	** --  ROA defined over the sample period
		restore, preserve
		bys siren : egen roa_mean =mean(roa)
		sum roa,d
		xtile roa_q = roa_mean, nq(4)
		foreach var in roa { 				
		gen low_`var' = ( `var'_q < 3) 
		}
		cap drop post_D D
		gen D = low_roa
		gen post_D = D * post
		cap drop cie_D_post cie_D
		gen cie_D_post = cie_post * D
		gen cie_D 	= cie * D
		
		lab var cie_D_post   "D $\times$ TC $\times$ Post"
		lab var cie_D		 "TC $\times$ D"
		lab var post_D       "D  $\times$ Post"
		
		reghdfe firm_with_ip cie_D_post cie_post post_D cie_D cie  $additional_control  $control $control_post,  $regspec_c
		outreg2 firm_with_ip cie_D_post post_D cie_D cie cie_post  $additional_control  $control $control_post using table9, bdec(4) rdec(3) keep(firm_with_ip cie_D_post post_D cie_D cie cie_post) excel  /*tex*/ append label
	
	
	// Table 10 - Effect of firms’ trade credit position on their payment default conditional on hedging liquidity risk

	** -- Cash holdings above median
		restore, preserve
		xtile cash_q = cash_ta, nq(4)
		foreach var in cash  { 				
		gen high_`var' = ( `var'_q > 3) 
		}
		
		cap drop post_D D
		gen D = high_cash
		gen post_D = D * post
		
		cap drop cie_D_post cie_D
		gen cie_D_post = cie_post * D
		gen cie_D 	= cie * D
		
		lab var cie_D_post   "D $\times$ TC $\times$ Post"
		lab var cie_D		 "TC $\times$ D"
		lab var post_D       "D  $\times$ Post"
		lab var D            "D"
		
		reghdfe firm_with_ip D cie_D_post cie_post post_D cie_D cie $additional_control  $control $control_post,  $regspec_c
		outreg2 firm_with_ip D cie_D_post post_D cie_D cie cie_post  $additional_control  $control $control_post using table10, bdec(4) rdec(3) keep(firm_with_ip cie_D_post post_D cie_D cie cie_post D) excel  /*tex*/ replace label
		
	** -- Accounts receivable management 
		restore, preserve
		
		replace af = 0 if af ==. | af < 0
		replace cc = 0 if cc ==. | cc < 0
		
		gen sum_client = af + cc
		gen receiv	 	= (bx+ys-dw)
		drop if receiv == 0 |receiv == . | receiv < 0
		
		** -- define on the sub pop with receiv > 0
		gen ratio_gestion = sum_client / receiv
		winsor ratio_gestion, gen(ratiow) p(0.01)
		
		gen  small = (taille_lme_string == "pme" | taille_lme_string == "mic")
	
		** -- Dummy: median conditional on having receivables and positive ratio
				cap drop gestion_dummy 
				sum ratiow if receiv > 0 & ratiow > 0,d
				cap drop gestion_dummy 
				
				xtile quartile_d = ratiow if receiv > 0 & ratiow > 0, nq(4)
				gen gestion_dummy = (quartile_d>2 & quartile_d !=.)
	
				cap drop D post_D cie_D cie_D_post
				gen D = gestion_dummy
				gen post_D  = post * D
				gen cie_D	= cie_ca * D
				gen cie_D_post = cie_post * D 
			
			* All
			reghdfe firm_with_ip cie_D_post cie_post  post_D cie_D cie D $additional_control $control $control_post if receiv > 0,  $regspec_c
			outreg2 firm_with_ip cie_D_post cie_post  post_D cie_D cie D  $additional_control  $control $control_post using table10, bdec(4) rdec(3) keep(firm_with_ip cie_D_post post_D cie_D cie cie_post D)   excel  /*tex*/ append label
		
			* Small
			reghdfe firm_with_ip cie_D_post cie_post  post_D cie_D cie D  $additional_control $control $control_post if (taille_lme_string !="ge_") &  receiv > 0,  $regspec_c
			outreg2 firm_with_ip cie_D_post cie_post  post_D cie_D cie D $additional_control  $control $control_post using table10, bdec(4) rdec(3) keep(firm_with_ip cie_D_post post_D cie_D cie cie_post D)   excel  /*tex*/ append label
		
			* Large
			reghdfe firm_with_ip cie_D_post cie_post  post_D cie_D cie D  $additional_control $control $control_post if (taille_lme_string =="ge_") &  receiv > 0,  $regspec_c
			outreg2 firm_with_ip cie_D_post cie_post  post_D cie_D cie D  $additional_control  $control $control_post using table10, bdec(4) rdec(3) keep(firm_with_ip cie_D_post post_D cie_D cie cie_post D)   excel  /*tex*/ append label
			
	
	// Table 11: Impact of firms’ payment default due to illiquidity and disputes on the
	// likelihood of bankruptcy, before the Covid-19 period
		
	** -- This table is run on a different dataset including bankruptcy and payment default events info
	** -- 2017m4 - 2019m12
	
		global regspec_e  	"absorb (siren ind_y4) 	vce (cluster i.siren)"
		global cov			cie	cash_ta  leverage size

		use $mypath2\basic_pseudo_long_period, replace		
		* FE
		egen ind_y4 = group(year naf4d)
		
		* Non investment grade and non already under bankruptcy procedure
		cap drop low_rated
		gen  low_rated = (rating_num > 4 & rating_num !=12)
		
		lab var  defaillance 	    		"Bankruptcy"
		lab var  at_least_one_dispute_3m 	"At least one dispute default 3m"
		lab var  at_least_one_illiq_3m		"At least one liquidity default 3m"
		lab var  cie						"Trade Credit t-1"
		lab var  cash_ta    				"Cash holdings t-1"
		lab var  leverage 					"Leverage t-1"
		lab var  size						"Size t-1"
		lab var  low_rated   	 			"Low credit rating t-1"
		
		reghdfe defaillance at_least_one_illiq_3m at_least_one_dispute_3m $cov low_rated  if year < 2020  , $regspec_e
		gen sample=e(sample)
		keep if sample ==1
		
		** Bankruptcy and at least one dispute over 3 months
		reghdfe defaillance   at_least_one_dispute_3m if year < 2020 , $regspec_e
		outreg2 defaillance   at_least_one_dispute_3m using table11, bdec(5) rdec(3) keep( at_least_one_dispute_3m) excel  /*tex*/ replace label
		
		** Bankruptcy and at least one illiquidity event over 3 months
		reghdfe defaillance   at_least_one_illiq_3m	  if year < 2020 , $regspec_e
		outreg2 defaillance   at_least_one_illiq_3m   using table11, bdec(5) rdec(3) keep(at_least_one_illiq_3m ) excel  /*tex*/ append label
		
		** Bankruptcy and both types of events
		reghdfe defaillance   at_least_one_illiq_3m at_least_one_dispute_3m	  if year < 2020 , $regspec_e
		outreg2 defaillance   at_least_one_illiq_3m at_least_one_dispute_3m   using table11, bdec(5) rdec(3) keep(at_least_one_illiq_3m at_least_one_dispute_3m) excel  /*tex*/ append label
		
		** Add covariates
		reghdfe defaillance at_least_one_illiq_3m at_least_one_dispute_3m  $cov if year < 2020  , $regspec_e
		outreg2 defaillance at_least_one_illiq_3m at_least_one_dispute_3m  $cov using table11, bdec(5) rdec(3) keep(at_least_one_illiq_3m at_least_one_dispute_3m $cov) excel  /*tex*/ append label
		
		** Risky rating
		reghdfe defaillance low_rated   at_least_one_illiq_3m at_least_one_dispute_3m $cov if year < 2020  , $regspec_e
		outreg2 defaillance low_rated   at_least_one_illiq_3m at_least_one_dispute_3m  $cov using table11, bdec(5) rdec(3) keep(at_least_one_illiq_3m at_least_one_dispute_3m $cov low_rated) excel  /*tex*/ append label
		
// Table 12 - Robustness: Does firms’ gross accounts receivable and/or payable explain
// firms’ payment default during the Covid-19 crisis?		
	
		restore, preserve
		
		foreach var in cie_post ccca_post dfac_post cie ccca dfac {
		replace `var' = 0 if `var' ==.
		}
		
		** Receivables 
		reghdfe firm_with_ip ccca_post ccca $additional_control $control $control_post  , $regspec_c
		outreg2 firm_with_ip ccca_post ccca $additional_control $control $control_post using table12, bdec(4) rdec(3) keep(firm_with_ip  ccca_post ccca) excel  /*tex*/ replace label
		
		** Payables 
		reghdfe firm_with_ip dfac dfac_post $additional_control $control $control_post , $regspec_c
		outreg2 firm_with_ip dfac dfac_post $additional_control $control $control_post using table12, bdec(4) rdec(3) keep(firm_with_ip  dfac dfac_post) excel  /*tex*/ append label
		
		** Receivables and Payables
		reghdfe firm_with_ip  ccca_post dfac_post ccca dfac $additional_control $control $control_post , $regspec_c
		outreg2 firm_with_ip  ccca_post ccca dfac dfac_post $additional_control $control $control_post using table12, bdec(4) rdec(3) keep(firm_with_ip  ccca_post ccca dfac dfac_post) excel  /*tex*/ append label
		

// Table 13 - Robustness tests to the dependent variable: Does firms’ trade credit
// position explain the intensity of firms’ payment default during the Covid-19 crisis?
		
		restore, preserve
		
		foreach var in aud_ca{
		replace `var' = 0 if `var' == .
		}
		
		label var aud_ca  "Amount under default over sales"
		label var nb 	  "Number of default"
		label var montant_mensuel_ip "Monthly cumulated amount under default" 
	
		* Nb default
		replace nb=0 if nb == .
		gen ln_nb_default = ln(1+nb)
		reghdfe ln_nb_default cie cie_post $additional_control  $control $control_post if  date < tm(2020m7) , $regspec_c
		outreg2 ln_nb_default cie cie_post $additional_control  $control $control_post using table13, bdec(4) rdec(3) keep(ln_nb_default cie cie_post) excel  /*tex*/ replace label
		
		* Multiple defaults
		gen more_than_1 = (nb_> 1)
		reghdfe more_than_1  cie cie_post $additional_control $control $control_post if  date < tm(2020m7) , $regspec_c
		outreg2 more_than_1  cie cie_post $additional_control $control $control_post using table13, bdec(4) rdec(3) keep(more_than_1  cie cie_post) excel  /*tex*/ append label
		
		* Amount under default		
		reghdfe aud_ca  cie cie_post $additional_control $control $control_post if  date < tm(2020m7) , $regspec_c
		outreg2 aud_ca  cie cie_post $additional_control $control $control_post  using table13, bdec(4) rdec(3) keep(aud_ca  cie cie_post) excel  /*tex*/ append label
		
		* Log AuD
		replace montant_mensuel_ip = 0 if montant_mensuel_ip ==.
		gen ln_aud =ln(montant_mensuel_ip + 1)
		sum ln_aud,d
		reghdfe ln_aud  cie cie_post $additional_control $control $control_post if  date < tm(2020m7) , $regspec_c
		outreg2 ln_aud  cie cie_post $additional_control $control $control_post  using table13, bdec(4) rdec(3) keep(ln_aud  cie cie_post) excel  /*tex*/ append label
		
// Table 14 - Robustness tests to the sample composition and to the specification
			
		restore, preserve
		
		** -- Robustness : fyend in Dec
		reghdfe firm_with_ip cie cie_post $additional_control $control $control_post  if  fmonth == 12, $regspec_c
		outreg2 firm_with_ip cie cie_post $additional_control $control $control_post  using table14, bdec(4) rdec(3) keep(firm_with_ip cie cie_post ) excel  /*tex*/ replace label
		
		** -- Independent firms only : lack the benefits of internal capital markets
		gen inde = (indic_gr == "0" )
		reghdfe firm_with_ip cie cie_post $additional_control $control $control_post  if inde ==1 , $regspec_c
		outreg2 firm_with_ip cie cie_post $additional_control $control $control_post  using table14, bdec(4) rdec(3) keep(firm_with_ip cie cie_post ) excel  /*tex*/ append label
		
		** -- UNBalanced panel
		use $mypath2\basic_pseudo_sample_unbalanced, clear
		reghdfe firm_with_ip cie cie_post $control $control_post  , $regspec_c
		outreg2 firm_with_ip cie cie_post $control $control_post  using table14, bdec(4) rdec(3) keep(firm_with_ip cie cie_post ) excel  /*tex*/ append label
		
		** -- Cluster industry at 4 digit level	
		restore, preserve
		reghdfe firm_with_ip cie cie_post $additional_control $control $control_post, absorb (siren ind_month) vce (cluster i.naf4d)
		outreg2 firm_with_ip cie cie_post $additional_control $control $control_post  using table14, bdec(4) rdec(3) keep(firm_with_ip cie cie_post ) excel  /*tex*/ append label
		
		** -- Finer sets of FE
		**  FE size x month ; location x month 
		gen 	taille_class = (taille_lme_st =="mic" | taille_lme_st =="...")
		replace taille_class = 2 if taille_lme_st =="pme"
		replace taille_class = 3 if taille_lme_st =="eti"| taille_lme_st =="ge_"
		egen size_time = group(taille_class date)
		
		** County x Time FE
		egen loc_time = group(depart date)
		reghdfe firm_with_ip cie cie_post $additional_control $control $control_post , absorb (siren size_time ind_month) vce (cluster i.siren)
		outreg2 firm_with_ip cie cie_post $additional_control $control $control_post  using table14, bdec(4) rdec(3) keep(firm_with_ip cie cie_post ) excel  /*tex*/ append label
		
		** Size x time FE
		reghdfe firm_with_ip cie cie_post $additional_control $control $control_post , absorb (siren loc_time ind_month) vce (cluster i.siren)
		outreg2 firm_with_ip cie cie_post $additional_control $control $control_post  using table14, bdec(4) rdec(3) keep(firm_with_ip cie cie_post ) excel  /*tex*/ append label
		
		** Both
		reghdfe firm_with_ip cie cie_post $additional_control $control $control_post, absorb (siren size_time loc_time ind_month) vce (cluster i.siren)
		outreg2 firm_with_ip cie cie_post $additional_control $control $control_post  using table14, bdec(4) rdec(3) keep(firm_with_ip cie cie_post ) excel  /*tex*/ append label			
			

		****************************************************************************
		*																		   *
		*				3.	DESCRIPTIVE STATISTICS : Table 2 to 5   	  		   *
		*																		   *
		****************************************************************************
		
				
		// This code makes descriptive statistics tables
			
		// Table 2  - Monthly statistics on payment default and default intensity
		
		// In 2019
		**************************************************************
		restore, preserve
		**************************************************************
		keep if year == 2019
		replace montant_mensuel_ip = montant_mensuel_ip/1000
		
		lab var firm_with_ip 		"Payment default dummy"
		lab var montant_mensuel_ip   "Amount under default in Keuros"
		
		local vartab firm_with_ip 
		eststo table0a :  estpost tabstat `vartab' , s(mean p50 p95 p99 sd N) col(s) 
			
		// Amount conditional on defaulting
		
		keep if firm_with_ip ==1
		local vartab montant_mensuel_ip 
	
		eststo table0b :  estpost tabstat `vartab' , s(mean p50 p95 p99 sd N) col(s) 
				
		
		// Table 3 and 4 : Firm-level statistics 
		
		***************************************************************	
		restore, preserve
		***************************************************************
		
		reghdfe firm_with_ip  cie_march cie_may cie $additional_control $control $control_post if date < tm(2020m7) , $regspec_c
		keep if e(sample) == 1
		
		gen  small = (taille_lme_string == "pme" | taille_lme_string == "mic")
		
		** -- In M euros
		foreach var in mobilisables endfi2 ta_lag {
		replace `var' = `var' /1000
		}
		
		foreach var in fl {
		replace `var' = `var' /1000
		}
	
		foreach var in fl ccca cie dfac ta_lag yp cash_ta endfi2 mobilisables leverage intexp_det chpers_ca chloc_ca roa {
		replace `var' = 0 if `var' == .
		}
				
		collapse (last) altman_w ratio_douteux fl ccca cie dfac small ta_lag yp cash_ta endfi2 mobilisables leverage  intexp_det chpers_ca chloc_ca   roa , by(siren year)
		
		collapse (last) small (mean) altman_w ratio_douteux fl ccca cie dfac  ta_lag yp cash_ta endfi2 mobilisables leverage intexp_det chpers_ca chloc_ca   roa , by(siren)
		
		*******************************
		save $mypath2\temp_stat2, replace
		*******************************
		
		// Table 4 - Main characteristics of in sample firms
		// Firm-level characteristics (2018-2019)
		*******************************
		use  $mypath2\temp_stat2, replace
		*******************************
		lab var ccca 			"Receivables to sales"
		lab var cie				"Net trade credit to sales"
		lab var dfac 			"Payables to purchases"
		
		lab var fl 				"Sales in million euros"
		lab var ta_lag  		"Total assets"
		lab var yp 		 		"N of employees"
		lab var cash_ta  		"Cash holdings to assets"
		lab var leverage		"Leverage (Debt to assets)"
		lab var endfi2			"Debt in million euros"
		lab var intexp_det		"Apparent cost of debt"
		lab var chpers_ca 		"Wages and benefits to sales"
		lab var chloc_ca		"Rents to sales"
		lab var ratio_douteux 	"Non-performing loans to total loans"
		lab var altman_w   		"Altman score"
		
		local vartab  cie ccca dfac ta_lag fl yp cash_ta endfi2 leverage  intexp_det ratio_douteux altman_w chpers_ca chloc_ca 
		estpost tabstat `vartab' , s(mean  p5 p25 p50 p75 p95  sd N) col(s) 
		
		*******************************
		use  $mypath2\temp_stat2, replace
		*******************************
		keep siren
		duplicates drop
		save $mypath2\list_firm, replace
		
		// Financing constraints and hedging
		***************************************************************
		restore, preserve		
		***************************************************************
		merge m:1 siren using $mypath2\list_firm
		keep if _m == 3
		
		** -- Last known pre Covid rating of the firm
		gen last_rating  = rating_num if year == 2019
		gen last_rating2 = rating_num if year == 2018
		
		bys siren : egen max_fy =max(year)
		bys siren : egen firm_last_rating  = max(last_rating) if max_fy == 2019
		bys siren : egen firm_last_rating2 = max(last_rating) if max_fy == 2018
		replace firm_last_rating = firm_last_rating2 if max_fy == 2018
		drop firm_last_rating2
		
		** -- High Yied rating or Rating 0
		cap drop low_rated
		gen low_rated = (firm_last_r > 4 |firm_last_r == 0)
		
		** -- Receivables and Payables
		gen receiv	 	= (bx+ys-dw)
		gen payb 	 	= dx-bv	
		
		** -- Dividend payer if paid dividend in 2018 and 2019
		bys siren : egen div_mean =mean(payer)
		gen non_payer =(div_mean ==0)
		gen D_div = non_payer
		
		** -- ARF
		replace af = 0 if af ==. | af < 0
		replace cc = 0 if cc ==. | cc < 0
		
		gen sum_client = af + cc
			
		gen ratio_gestion = sum_client / receiv
		replace ratio_gestion = . if  receiv == 0 |receiv == . | receiv < 0
				
		winsor ratio_gestion, gen(ratiow) p(0.01)
		mdesc ratio_gestion
		
		gen  small = (taille_lme_string == "pme" | taille_lme_string == "mic")
		
		save $mypath2\temp, replace

		** 
		use $mypath2\temp, replace
		collapse (last) roa small low_rated  D_div , by(siren year)
		
		collapse (last) small (mean)   roa  low_rated D_div  , by(siren)
		
		*******************************
		save $mypath2\temp_stat3, replace
		*******************************
		
		lab var roa				"Return on assets"
		lab var low_rated		"Risky credit rating dummy"
		lab var	D_div			"Non dividend payer dummy"
		lab var small			"Small firm dummy"
		
		local vartab  roa  low_rated D_div small
		eststo table1 :  estpost tabstat `vartab' , s(mean p5 p25 p50 p75 p95 sd N) col(s) 
				
		
		**  MRPK
		*********************************
		use $mypath2\ind_mrpk, replace
		*********************************
		keep siren date mean_mrpk* mrpk*
		merge 1:1 siren date using $mypath2/basic_pseudo_sample.dta
		keep if _m ==3
		
		foreach var in mean_mrpk1  { 				
		gen high_`var' = ( mrpk1_q > 2) 
		}
		
		keep siren year  mean_mrpk1 mrpk1_q
		
		foreach var in mean_mrpk1  { 				
		gen high_`var' = ( mrpk1_q > 2) 
		}
		
		collapse (last) mean_mrpk1 high_mean_mrpk1 , by(siren)
		merge m:1 siren using $mypath2\list_firm
		keep if _m == 3
		
		lab var mean_mrpk 			"Value added to capital"
		lab var high_mean_mrpk 		"High MRPK dummy"
		
		local vartab  mean_mrpk high_mean_mrpk 
		eststo table1 :  estpost tabstat `vartab' , s(mean p5 p25 p50 p75 p95 sd N) col(s) 
					
					
		// Table 5 - Firm-level statistics by sector
		
		****************************************************************
		restore, preserve
		****************************************************************
		reghdfe firm_with_ip  cie_march cie_may cie $additional_control $control $control_post if date < tm(2020m7) , $regspec_c
		keep if e(sample) == 1
		
		distinct siren
		
		gen 	main_sector="Agriculture" 	if naf>=00 & naf<=04
		replace main_sector="Manufacturing" 		if naf>=05 & naf<=39
		replace main_sector="Construction" 	if naf>=41 & naf<=43
		replace main_sector="Trade" 							if naf>=45 & naf<=47
		replace main_sector="Transport, storage" 				if naf>=49 & naf<=53
		replace main_sector="Accomodation, food" 		if naf>=55 & naf<=56
		replace main_sector="Information" 		if naf>=58 & naf<=63
		replace main_sector="Finance" 			if naf>=64 & naf<=66
		replace main_sector="Real estate" 		if naf>=68 & naf<=68
		replace main_sector="Corporate Services" 			if naf>=69 & naf<=82 
		replace main_sector="Health" 			if naf>=84 & naf<=88
		replace main_sector="Recreation" 		if naf>=90		
		replace	main_sector="Wholesale trade" 	if naf==46
		replace main_sector="Retail trade" 		if naf==47 | naf==45
					
		egen ind_num = group(main_sector)
		
		save $mypath2\temp_stat, replace
		
	
		** -- By Industry
		forvalues i = 1(1)12 {
		use $mypath2\temp_stat, replace
		collapse (mean) ccca cie_ca dfac firm_with_ip (last) main_sector ind_num ,by(siren)
		
		lab var ccca 			"Receivables to sales"
		lab var cie				"Net trade credit to sales"
		lab var dfac 			"Payables to purchases"
		
		keep if ind_num ==  `i'
		estadd local Industry 		= main_sector , replace
		local vartab cie dfac ccca 
		eststo table`i' :  estpost tabstat `vartab', s(mean p5 p25 p50 p75 p95 sd N) col(s) 
		}
			
		****************************************************************************
		*																		   *
		*					4.			FIGURES				   	  				   *
		*																		   *
		****************************************************************************
		
		// Figure 7 - Dynamic effect 
		*---------------------------------------------------------------------------------------------*
		
		global control		 		cash_ta 	  leverage 		 size
		global control_post			cash_ta_post  leverage_post  size_post
		global regspec_c  			"absorb (siren ind_month) vce (cluster i.siren)"		
		
		****************************************************************
		restore, preserve
		*****************************************************************
		keep siren
		duplicates drop
		*********************************************
		save $mypath2\siren_sample, replace
		*********************************************
		
		** We do the graph on a longer time period than the one used for the baseline results
		** but for the same firms as the ones that are in our regression sample
		use $mypath2\basic_pseudo_sample_unbalanced, clear		
		merge m:1 siren using $mypath2\siren_sample
		keep if _m ==3 
		tab date
		
		** Monthly time dummies
		cap drop m_date cie_dum*
		
		egen m_date = group(date)
		local m1 = 1
		local m2 = 24
		forvalues m=`m1'/`m2' {
			gen cie_dum_`m' = cie *(m_date==`m')
		}
				
		local m1 = 1
		local m2 = 6
		forvalues m=`m1'/`m2' {
			replace cie_dum_`m' = 0
		}
		
		
		parmby "reghdfe firm_with_ip cie cie_dum* $control $control_post , $regspec_c", norestore
		sencode parm, gen(parmid)
			
		**
		cap drop time_span
		gen time_span = substr(parm,1,3)
		keep if time_span == "cie"
		
		cap drop date_m
		gen date_m = parmseq
		
		** Input the first monthly date as time_ref :
		gen time_ref = tm(2019m7)
		
		cap drop time
		gen time = time_ref if parmseq == 8
		forvalues i = 1(1)18 {
		replace time = time_ref + `i' if parmseq == 8 + `i'
		}
		format time %tm
		
		
			eclplot estimate min95 max95 time, xlabel(,  labsize(small)) ///
			graphregion(color(white)) ///
			xlab(713(2)731) ylab(-0.006(0.002)0.006) xline(722.2, lcolor(gs14) lw(vvvthick)) xline(722.5, lcolor(gs14) lw(vvvthick)) xline(722.85, lcolor(gs14) lw(vvvthick))   ///
			xline(730, lcolor(gs14) lw(vvvthick)) xline(730.2, lcolor(gs14) lw(vvvthick))   ///
			yline(0, lcolor(black) lstyle(dot)) xtitle("") ytitle("Monthly coefficient estimates")
		
		
		keep estimate min95 max95 time
		save $mypath2\main_graph, replace
		
		// Figure 8 - Zoom on retail trade
		/*
		*---------------------------------------------------------------------------------------------*
		// 
		***********************************************************
		use $mypath2\basic_pseudo_sample_unbalanced, clear
		***********************************************************
		merge m:1 siren using $mypath2\siren_sample
		keep if _m ==3 
		
		** Monthly time dummies
		cap drop m_date cie_dum*
		
		egen m_date = group(date)
		local m1 = 1
		local m2 = 24
		forvalues m=`m1'/`m2' {
			gen cie_dum_`m' = cie *(m_date==`m')
		}
		
		keep if naf==47 | naf==45
		
		local m1 = 1
		local m2 = 6
		forvalues m=`m1'/`m2' {
			replace cie_dum_`m' = 0
		}
		
		
		parmby "reghdfe firm_with_ip cie cie_dum* $control $control_post  , $regspec_c", norestore
		sencode parm, gen(parmid)
			
		**
		cap drop time_span
		gen time_span = substr(parm,1,3)
		keep if time_span == "cie"
		
		cap drop date_m
		gen date_m = parmseq
		
		** Input the first monthly date as time_ref :
		gen time_ref = tm(2019m7)
		
		cap drop time
		gen time = time_ref if parmseq == 8
		forvalues i = 1(1)18 {
		replace time = time_ref + `i' if parmseq == 8 + `i'
		}
		format time %tm
		
		keep estimate min95 max95 time

		save $localpath\temp, replace
		use $localpath\temp, replace
		gen industry ="Retail trade"
		
		append using $mypath\main_graph
		
		replace industry ="All industry" if industry==""
		drop if time ==.
		
			eclplot estimate min95 max95 time,  xlabel(,  labsize(small)) ///
			graphregion(color(white)) ///
			xlab(713(2)731) ylab(-0.02(0.01)0.025) xline(722.2, lcolor(gs14) lw(vvvthick)) xline(722.5, lcolor(gs14) lw(vvvthick)) xline(722.85, lcolor(gs14) lw(vvvthick))   ///
			xline(730, lcolor(gs14) lw(vvvthick)) xline(730.2, lcolor(gs14) lw(vvvthick))   ///
			yline(0, lcolor(black) lstyle(dot)) xtitle("") ytitle("Monthly coefficient estimates") ///
			supby(industry, spaceby(0.25))
			
	*/
